package com.androidx.p013lv.mine.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import androidx.fragment.app.FragmentActivity;
import com.androidx.p013lv.base.utils.ImageUtil;
import com.androidx.p013lv.base.utils.QRCodeUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.mine.C1207R;
import java.util.Objects;
import p000a.p002b.RxPermissions;
import p023io.reactivex.functions.Consumer;

/* renamed from: com.androidx.lv.mine.dialog.AddWeChatDialog */
public class AddWeChatDialog extends Dialog {
    private Context context;
    ImageView weChatCode = ((ImageView) findViewById(C1207R.C1210id.img_code_we_chat));

    public AddWeChatDialog(Context context2) {
        super(context2, C1207R.C1214style.MyDialogStyle);
        this.context = context2;
        ((Window) Objects.requireNonNull(getWindow())).setGravity(17);
        setContentView(C1207R.C1212layout.dialog_add_wx_layout);
        setCanceledOnTouchOutside(true);
        findViewById(C1207R.C1210id.tv_negative).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.dialog.AddWeChatDialog.View$OnClickListenerC12901 */

            public void onClick(View view) {
                AddWeChatDialog.this.dismiss();
            }
        });
        findViewById(C1207R.C1210id.tv_positive).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.dialog.AddWeChatDialog.View$OnClickListenerC12912 */

            public void onClick(View view) {
                AddWeChatDialog addWeChatDialog = AddWeChatDialog.this;
                addWeChatDialog.requestPermission(addWeChatDialog.loadBitmapFromView(addWeChatDialog.weChatCode));
                AddWeChatDialog.this.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void requestPermission(final Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= 23) {
            new RxPermissions((FragmentActivity) this.context).request("android.permission.WRITE_EXTERNAL_STORAGE").subscribe(new Consumer<Boolean>() {
                /* class com.androidx.p013lv.mine.dialog.AddWeChatDialog.C12923 */

                public void accept(Boolean bool) throws Exception {
                    if (bool.booleanValue()) {
                        ImageUtil.saveImageToGallery(AddWeChatDialog.this.context, bitmap);
                    } else {
                        ToastUtils.getInstance().showSigh("未授權權限，請在設置中允許權限");
                    }
                }
            });
        } else {
            ImageUtil.saveImageToGallery(this.context, bitmap);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private Bitmap loadBitmapFromView(View view) {
        Bitmap createBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(createBitmap);
        canvas.drawColor(-1);
        view.draw(canvas);
        return createBitmap;
    }

    public void setWeChatCodeUrl(String str) {
        this.weChatCode.setImageBitmap(QRCodeUtil.createQRCode(str, UiUtils.dp2px(120)));
    }
}
